#!/bin/bash
yes y | head -1 | yum install expect
yum install -y vsftpd
systemctl enable vsftpd.service
systemctl start vsftpd.service
useradd $1
/usr/bin/expect << EOF
spawn passwd $1
expect "New password:"
send "$2\r"
expect "Retype new password:"
send "$2\r"
expect eof
exit
EOF

mkdir -p /var/ftp/work01
chown -R $1:$1 /var/ftp/work01
sed -i "s/anonymous_enable=YES/anonymous_enable=NO/" /etc/vsftpd/vsftpd.conf
echo "local_root=/var/ftp/work01" >> /etc/vsftpd/vsftpd.conf
sed -i "s/listen=NO/listen=YES/" /etc/vsftpd/vsftpd.conf
sed -i "s/listen_ipv6=YES/listen_ipv6=NO/" /etc/vsftpd/vsftpd.conf
echo "chroot_list_enable=YES" >> /etc/vsftpd/vsftpd.conf
echo "pasv_address=$3" >> /etc/vsftpd/vsftpd.conf
echo "listen_port=10021" >> /etc/vsftpd/vsftpd.conf
echo "pasv_min_port=3000" >> /etc/vsftpd/vsftpd.conf
echo "pasv_max_port=3100" >> /etc/vsftpd/vsftpd.conf
touch /etc/vsftpd/chroot_list
systemctl restart vsftpd.service
netstat -antup | grep ftp